import type { PropType } from 'vue';

export const SizeType = {
  large: 'large',
  medium: 'medium',
  small: 'small',
  mini: 'mini'
} as const;

export type SizeType = (typeof SizeType)[keyof typeof SizeType];

export type TreeSelectOption = {
  valueKey: string;
  labelKey: string;
};

export type SSModelValue = TData | TData[] | undefined;

export interface SSFilterMethod {
  (value: any): boolean;
}

export interface TData {
  id: string;
  name: string;
  key?: string;
  type?: 1 | 2;
  children?: TData[];
  disabled?: boolean;
  [key: string]: any;
}

export const SelecterProps = {
  modelValue: {
    type: [Array, String] as PropType<string[] | string>,
    default: undefined
  },
  placeholder: {
    type: String as PropType<string>,
    default: '请选择'
  },
  disabled: {
    type: Boolean as PropType<boolean>,
    default: false
  },
  multiple: {
    type: Boolean as PropType<boolean>,
    default: false
  },
  size: {
    type: String as PropType<SizeType>,
    default: SizeType.medium
  },
  // 筛选项 不会显示再列表中
  filterMethod: {
    type: Function as PropType<SSFilterMethod>,
    default: undefined
  },
  // 禁用项 会显示在列表中
  disabledMethod: {
    type: Function as PropType<SSFilterMethod>,
    default: undefined
  },
  // 显示模式 select 选择框 button 按钮
  mode: {
    type: String as PropType<'select' | 'button'>,
    default: 'select'
  }
};

export const TreeSelectProps = {
  modelValue: {
    type: Object as PropType<SSModelValue>,
    default: undefined
  },
  placeholder: {
    type: String as PropType<string>,
    default: '请选择'
  },
  disabled: {
    type: Boolean as PropType<boolean>,
    default: false
  },
  multiple: {
    type: Boolean as PropType<boolean>,
    default: false
  },
  size: {
    type: String as PropType<SizeType>,
    default: SizeType.medium
  },
  options: {
    type: Array as PropType<TData[]>,
    required: true
  },
  type: {
    type: Number as PropType<1 | 2>,
    default: 1
  }
};

export const TreeSelectDailogProps = {
  modelValue: {
    type: Object as PropType<SSModelValue>,
    default: undefined
  },
  multiple: {
    type: Boolean as PropType<boolean>,
    default: false
  },
  loading: {
    type: Boolean as PropType<boolean>,
    default: false
  },
  visible: {
    type: Boolean as PropType<boolean>,
    default: false
  },
  title: {
    type: String as PropType<string>,
    default: '请选择'
  },
  options: {
    type: Object as PropType<TData[]>,
    default: () => []
  },
  type: {
    type: Number as PropType<1 | 2>,
    default: 1
  }
};
